package cn.peach.hrm.controller;

import cn.peach.hrm.dto.sendSmsCodeDto;
import cn.peach.hrm.service.IVerifyCodeService;
import cn.peach.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author you
 * @create 2021/12/2 11:54
 */
@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 创建图形验证码
     * @param key
     * @return
     */
    @GetMapping("/imageCode/{key}")
    public AjaxResult imageCode(@PathVariable("key") String key){
        String imageCode = verifyCodeService.imageCode(key);
        return AjaxResult.me().setResultObj(imageCode);
    }

    /**
     * 手机验证码
     * @param dto
     * @return
     */
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody sendSmsCodeDto dto){
        verifyCodeService.sendSmsCode(dto);
        return AjaxResult.me();
    }
}
